<template>
  <el-row>
    <el-card>
      <el-table
        v-loading="timeLoading"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        :data="creditTimeData"
        border
        :stripe="true"
        style="width: 100%"
      >
        <el-table-column
          :label="tableText['configurationContent']"
          min-width="150"
        >
          <template>
            {{ tableText['timeSetting'] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="morningStart"
          :label="tableText['morningStartTime']"
          min-width="150"
        />
        <el-table-column
          prop="morningEnd"
          :label="tableText['morningEndTime']"
          min-width="150"
        />
        <el-table-column
          prop="afternoonStart"
          :label="tableText['afternoonStartTime']"
          min-width="150"
        />
        <el-table-column
          prop="afternoonEnd"
          :label="tableText['afternoonEndTime']"
          min-width="150"
        />
        <el-table-column
          prop="employeeName"
          :label="tableText['updater']"
          min-width="100"
        />
        <el-table-column
          prop="modifyTime"
          :label="tableText['updateTime']"
          min-width="150"
        />
      </el-table>
    </el-card>
    <el-card>
      <el-table
        v-loading="numberLoading"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        :data="creditContentData"
        border
        :stripe="true"
        style="width: 100%"
      >
        <el-table-column
          prop="content"
          :label="tableText['configurationContent']"
          min-width="250"
        />
        <el-table-column
          prop="count"
          :label="tableText['number']"
          min-width="100"
        />
        <el-table-column
          prop="employeeName"
          :label="tableText['updater']"
          min-width="150"
        />
        <el-table-column
          prop="modifyTime"
          :label="tableText['updateTime']"
          min-width="150"
        />
        <el-table-column
          :label="$t('common.operate.name')"
          min-width="100"
        >
          <template slot-scope="scope">
            <el-button size="small" @click="editInfo(scope.row)">{{ $t('common.operate.edit') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <letter-review-dialog
      :show-dialog="editDialog"
      :choose-item="chooseItem"
      @change-dialog="changeDialog"
      @edit-success="editSuccess"
    />
  </el-row>
</template>

<script>
import letterReviewDialog from '@/components/risk/businessConfig/letter-review-dialog'
import { creditContent, creditTime } from '@/api/risk'
export default {
  name: 'LetterReview',
  components: {
    letterReviewDialog
  },
  data() {
    return {
      creditTimeData: [],
      timeLoading: true,
      creditContentData: [],
      numberLoading: true,
      editDialog: false,
      tableText: {},
      chooseItem: {
        count: null,
        id: null
      }
    }
  },
  mounted() {
    this.tableText = this.$t('BusinessConfig.letterReview')
    this.getCreditContent()
    this.getCreditTime()
  },
  methods: {
    getCreditContent() {
      creditContent()
        .then(res => {
          this.numberLoading = false
          if (res.success) {
            this.creditContentData = [res.data]
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {
          this.$message.error(err.message)
          this.numberLoading = false
        })
    },
    getCreditTime() {
      creditTime()
        .then(res => {
          this.timeLoading = false
          if (res.success) {
            console.log(res.data)
            this.creditTimeData = [res.data[1]]
            console.log(this.creditTimeData)
            console.log(this.creditTimeData)
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {
          this.$message.error(err.message)
          this.timeLoading = false
        })
    },
    editInfo(data) {
      this.choose(data)
      this.editDialog = true
    },
    changeDialog(param) {
      this.editDialog = param
      setTimeout(() => {
        this.choose({})
      }, 10)
    },
    editSuccess() {
      this.getCreditContent()
    },
    choose(params) {
      this.chooseItem.id = params.id
      this.chooseItem.count = params.count
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card{
  margin: 10px;
}
</style>
